let isNavigating = false // 节流状态标记
let lastNavTime = 0 // 新增时间戳记录

const simpleGo = (path, params = {}, options = {} , isTab) => {
  console.log(path, isTab)
  const now = Date.now()
  // 时间间隔检查（800ms限制）
  if (isNavigating || now - lastNavTime < 800) return
  
  isNavigating = true
  lastNavTime = now
  
  // 参数序列化
  const query = Object.keys(params).map(k => `${k}=${encodeURIComponent(params[k])}`).join('&')
  const url = query ? `${path}?${query}` : path 
  // 自动识别跳转类型
  // const isTab = path.startsWith('/pages/tabBar/') // 示例条件，根据实际tab页面调整
  const method = options.redirect ? 'redirectTo' : isTab ? 'switchTab' : 'navigateTo'
  console.log(method, isTab)
  uni[method]({
    url,
    complete: () => {
      isNavigating = false // 完成后解除锁定
      options.complete?.()
    },
    fail: (err) => {
      isNavigating = false // 失败时也解除锁定
      console.error('路由跳转失败:', err)
      options.fail?.(err)
    }
  })
}

// 常用方法封装
const back = () => uni.navigateBack()
const redirect = (path, params) => simpleGo(path, params, { redirect: true })
const switchTab = (path, params) => {
	console.log('switchTab');
	simpleGo(path, params, { redirect: false }, true);
}

export default {
  go: simpleGo,
  back,
  redirect,
  switchTab
}